import { useSelector } from "react-redux"
import { Navigate } from "react-router-dom"
import type { UserStore } from "../type/StoreType"
import type { JSX } from "react"

function RouterEnter (props: { element: JSX.Element }) {
  const { user } = useSelector((state: { user: UserStore }) => state.user)
  if (!user.token) return <Navigate to="/login" />
  return props.element
}

export default RouterEnter
